Repository navigation
fix(search-events): Keep explicit timestamp bounds the agent drops - #2139
sentry-junior[bot] wants to merge 2 commits into
Conversation
When a structured query has timestamp:>= / timestamp:< bounds and the caller also passes period, the embedded agent often moves the bounds into an absolute timeRange and drops them from the query. The explicit period then wins over that range, so the search silently runs over the whole period instead of the requested window. Put any dropped timestamp bounds back on the repaired query. They only narrow the period, so they are safe to send. Grouped and boolean queries are left alone. Co-Authored-By: Sergiy Dybskiy <3760543+sergical@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
The grouping guard skipped restoring dropped timestamp bounds whenever a token contained a parenthesis, including parentheses inside a quoted value such as message:"err (timeout)". Strip quoted values before the check so only real grouping skips the restore.
|
We got another user report of this exact path on On main @ 0a3801e the cause is unchanged: The report also says the explanation didn't match what ran. That part is tracked in #2147. |
|
Another report of this path, from the same automated caller as the 11-12 report. This caller has now sent five reports since 11-08 (MCP-SERVER-GMH, GMK, GMZ, GP9, GPJ), on
I checked this PR against current main @ c8447f8. The diff still applies cleanly. The new regression test fails on main ( |
|
Another production report of this exact case: user feedback MCP-SERVER-GPW (2026-11-13, server 0.42.0, Trace evidence (same user, 2026-11-13 17:01–17:05Z, several
Checked against this branch: I added a scratch case with the reporter's query shapes to the regression test from this PR: bounds in the middle of the query, an Pattern count: I count 8 reports of One gap remains after this PR. The explanation can still say the range was converted to absolute bounds while |
|
Another report of this exact case: Sentry MCP feedback MCP-SERVER-GPV,
In the same session, 2 of the 6 The feedback also points out that the explanation claims absolute bounds were applied. That part is #2147. That makes at least 10 reports of this pattern in mcp-server feedback over the last 14 days. |
`search_issue_events` fails on open-ended "since X" windows such as
`timestamp:>=2026-11-12T06:39:00Z` or "since November 12 2026 at 06:39
UTC". It returns "The AI was unable to process your query";
`search_errors` handles the same window fine.
**Why it fails**
The embedded agent's output schema
(`tools/support/search-issue-events/agent.ts`) is stricter than its
prompt:
1. An absolute `timeRange` requires both `start` and `end`. A "since X"
request has no natural end, and the agent doesn't know the current time.
2. `timeRange` is required, but the prompt says to omit it for the
default window.
If the model returns `{start}` only, or omits `timeRange`, the AI SDK
raises `NoObjectGeneratedError` ("response did not match schema").
`rescueFromText` can't repair that, so the tool returns the "unable to
process" error (`internal/agents/callEmbeddedAgent.ts:226`). Production
logs show this exact error with `finishReason: stop` for these queries.
Which of the two shapes the model produced is inferred, since the traces
weren't sampled.
**Change**
- In an absolute `timeRange`, `end` is optional. When it's missing, the
handler runs the search until now.
- `timeRange` defaults to `null`, meaning the default 14d window.
- The prompt has open-ended examples and says "null" instead of "omit".
Existing outputs, whether full `{start, end}` or `{statsPeriod}`, behave
as before.
Related but separate: #1215 / #1228 (caller-supplied `start`/`end` for
`search_events` and `search_issues`) and #2139 / #2146 (dropped absolute
bounds in `runSearchEvents`). Longer term, #1896 removes the embedded
search agents.
<!-- junior-request-attribution:start -->
via @joshuarli.
<!-- junior-request-attribution:end -->
<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0CG2CP9ELW%3A1794596896.742009 -->
--
[View
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CG2CP9ELW%3A1794596896.742009)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CG2CP9ELW%3A1794596896.742009/?project=4510944073809921)
<!-- junior-session-footer:end -->
Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
… also passed (#2146) `search_errors` (and the other `runSearchEvents` tools) can silently search the whole `period` when the query names a fixed window. This happens when the caller names a window in the query text, uses some structured filters, and also sends `period` as an outer guard. **What happens** 1. The query has structured filters, so `hasStructuredQuery` is true. Dataset tools set `lockDataset`, so the handler trusts the caller's explicit params. 2. The embedded agent sees `statsPeriod` in its prompt. It still returns an absolute `timeRange` (`{start, end}`) for the window that the query names. 3. Because `period` is explicit, the handler discards that range and sends only `statsPeriod` (`search.ts:936-938` on main). `executedSearch.timeRange` shows `statsPeriod` with null `start`/`end`. The explanation still describes the agent's plan. A production trace from user feedback (MCP-SERVER-GN4) shows exactly this. The query was `Between <start> and <end>, environment:production <tag>:<value>, …` with `period: "3d"`. The agent's first `events/validate` call used `start`/`end`. The final `/events/` request and the Snuba query used the 3-day rolling window. The same session without structured filters took the untrusted path, and the absolute range was applied correctly. **Change** When the caller passes `period` and the agent returns an absolute range, the search uses the overlap of the two. The overlap can only narrow `period`, so the result never goes outside what the caller allowed. When the two don't overlap, or the agent returned a relative period, the caller's `period` is kept as before. **Relation to other work** - #2139 handles the case where the bounds are `timestamp:` tokens in the query. It puts them back on the query after the agent drops them. This PR covers bounds written in prose, where there are no tokens to put back. The two don't overlap in code, and both can land. - #1215 / #1228 (typed `start`/`end` inputs) is still the long-term fix for callers that know the exact window. - The Seer path has the same `explicit period wins` rule (`search.ts:851-853`). I left it unchanged because I have no trace evidence for it. <!-- junior-request-attribution:start --> via **Sentry**. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0CG2CP9ELW%3A1794328376.548829 --> -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CG2CP9ELW%3A1794328376.548829) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CG2CP9ELW%3A1794328376.548829/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
search_errorsand the otherrunSearchEventstools can silently run a fixed-window search over the wholeperiod. This happens when the caller sends a structured query withtimestamp:>=/timestamp:<bounds and aperiod.What happens
timeRange({start, end}).period, the handler keepsperiodand discards the agent'stimeRange(search.ts:936-938on main).The only guard on the agent's rewrite is
isSemanticFilterDowngrade, and it only catches filters rewritten into full-text matching. It does not catch filters that were dropped.User feedback reported this more than once: automated callers asked for fixed windows and got rolling-period totals back. In production traces, the agent returned an absolute
timeRangefor the requested window, and the final/events/request still used the caller'sstatsPeriod.Change
After the agent repairs a structured query, any
timestamp:bounds from the caller's query that are missing from the repaired query are appended to it again. The bounds can only narrow the period, so sending them is always safe. Queries withOR/ANDor parentheses are left unchanged, because a bound appended outside its group would change what it means.The regression test sets up this case:
period: "7d", the agent moves the bounds intotimeRangeand drops them from the query, and the request must still carry them. Without the fix, the request query has no bounds.Out of scope: exposing
start/endas tool inputs, which is #1215 / #1228. That work does not cover this path, where aperiodis passed alongside bounds in the query.via @sergical.
--
View Session [Sentry]